import { create } from './asyncActionCreator';
import { MODIFY_PASSWORD_URL } from '../../../constants/API';

/**
 * 重置修改密码页面状态
 * @type {String}
 */
export const RESET_MODIFY_PASSWORD = 'reset modify password';
export const resetModifyPassword = () => ({
	type:RESET_MODIFY_PASSWORD,
	payload:{}
})
/**
 * 请求修改密码
 * @type {String}
 */
export const MODIFY_PASSWORD_REQUEST = 'modify password request',
			 MODIFY_PASSWORD_SUCCESS = 'modify password success',
			 MODIFY_PASSWORD_FAILURE = 'modify password failure';

export const modifyPasswordRequest = () => ({
	type: MODIFY_PASSWORD_REQUEST,
	payload: {}
});

export const modifyPasswordSuccess = () => ({
	type: MODIFY_PASSWORD_SUCCESS,
	payload: {}
});

export const modifyPasswordFailure = (errorMessage) => ({
	type: MODIFY_PASSWORD_FAILURE,
	payload: {
		errorMessage
	}
});

export const modifyPassword = ({oldPassword,newPassword,securityCode,userName}) => {

	let params = {
		mobile: userName,
		password: oldPassword,
		new_password: newPassword,
		security_code: securityCode
	};

	return create(MODIFY_PASSWORD_URL,
		modifyPasswordRequest,
		modifyPasswordSuccess,
		modifyPasswordFailure,
		params);
};